package cronjob

import (
	"context"
	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
	"go-zero-admin/application/job/api/internal/svc"
	"go-zero-admin/application/job/api/internal/types"
	"go-zero-admin/application/job/rpc/pb"
)

type DeleteCronLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 删除定时任务
func NewDeleteCronLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCronLogic {
	return &DeleteCronLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteCronLogic) DeleteCron(req *types.DeleteCronReq) (resp *types.DeleteCronRes, err error) {
	res, err := l.svcCtx.JobCronSvc.DeleteCron(l.ctx, &pb.DeleteCronReq{
		TaskId: uint32(req.TaskId),
	})
	if err != nil {
		return nil, err
	}
	resp = &types.DeleteCronRes{}
	_ = copier.Copy(resp, &res)
	return resp, nil
}
